#include "AppDelegate.h"

#include "LoseLayer.h"

AppDelegate::AppDelegate()
{
}

AppDelegate::~AppDelegate()
{
    SimpleAudioEngine::end();
}

bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    CCDirector *pDirector = CCDirector::sharedDirector();
	CCEGLView* eglView= CCEGLView::sharedOpenGLView();
    pDirector->setOpenGLView(eglView);

	//set auto scale
	pDirector->getOpenGLView()->setDesignResolutionSize(_960, _1600, kResolutionExactFit);

    // turn on display FPS
    //pDirector->setDisplayStats(true);

    // set FPS. the default value is 1.0/60 if you don't call this
    pDirector->setAnimationInterval(1.0f / NT_FPS_DEFAULT);

	srand (time(NULL));

	NTUserDefault::sharedUserDefault()->setIntegerForKey(KEY_SELECT_LEVEL, 2);

	CCScene *pScene = CCScene::create();
	pScene->addChild(MainMenuLayer::create(), 2);
	pScene->addChild(GAMELAYER::create(), 1, 999);

    // run
    pDirector->runWithScene(pScene);
    return true;
}

// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground()
{
    CCDirector::sharedDirector()->stopAnimation();

    SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
	SimpleAudioEngine::sharedEngine()->pauseAllEffects();
}

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
{
    CCDirector::sharedDirector()->startAnimation();

    SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
	SimpleAudioEngine::sharedEngine()->resumeAllEffects();
}
